import mysql.connector
from PyQt5.QtWidgets import QMessageBox

from src.admin.FineMag_UI import Ui_Form
from PyQt5 import QtWidgets
from src.admin.FineMsgAlter_Win import FineMsgAlter_Win
from src.admin.myAllFine_win import AllFine_Win


class FineMag_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb,parent=None):
        super(FineMag_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.LoginSignal=False
        self.mydb= mydb

        self.MsgAlter_form=FineMsgAlter_Win(self.mydb)
        self.AllFine_form=AllFine_Win(self.mydb)

        self.MsgAlter_form.setWindowTitle("罚款查询")
        self.AllFine_form.setWindowTitle("全部罚款")

    def myMsgAlter(self):
        s=self.lineEdit.text()
        myselect = "select * from 罚款信息表 where 罚款单号 =" + s
        try:
            mycursor = self.mydb.cursor()
            mycursor.execute(myselect)
        except Exception as a:
            QMessageBox.critical(self, '错误', '信息不正确')
        else:
            result = mycursor.fetchall()
            if len(result)==0:
                QMessageBox.critical(self, '错误', '信息不正确')
            else:
                self.MsgAlter_form.label_5.setText(str(result[0][0]))
                self.MsgAlter_form.label_6.setText(str(result[0][1]))
                self.MsgAlter_form.label_9.setText(str(result[0][2]))
                self.MsgAlter_form.label_10.setText(str(result[0][3]))
                self.MsgAlter_form.label_12.setText(str(result[0][4]))
                self.MsgAlter_form.label_13.setText(result[0][5])
                self.MsgAlter_form.show()

    def myAllFine(self):
        self.AllFine_form.myTable_init()
        self.AllFine_form.show()

    def myOut(self):
        self.hide()

    def getMydb(self,mydb):
        self.mydb=mydb
        self.MsgAlter_form.getMydb(mydb)
        self.AllFine_form.getMydb(mydb)

